extends CardState

# 死区设置--当进入此状态0.05秒后，才响应输入
var TIME=0.05
var isActive=false

func enter()->void:
	if !state:return push_error('状态未分配')
	var ui=get_tree().get_first_node_in_group('battleUI')
	if ui:card.reparent(ui)

	Events.cardDragStarted.emit(card)
	setStyle(card.DRAG)

	isActive=false
	var timer=get_tree().create_timer(TIME,false)
	timer.timeout.connect(func():isActive=true)

func exit()->void:
	Events.cardDragEnded.emit(card)
	  
func onInput(event:InputEvent)->void:
	if !isActive:return

	var single := card.cardSrc.isSingle()
	var motion := event is InputEventMouseMotion
	var cancel := event.is_action_pressed('right_mouse')
	var confirm = event.is_action_released('left_mouse') or event.is_action_pressed('left_mouse')

	# 进入瞄准状态
	if single and motion and card.placeArea:
		return transition.emit(self,State.AIMING)

	if motion:
		card.global_position=card.get_global_mouse_position()-card.pivot_offset
	if cancel:
		transition.emit(self,State.BASE)
	elif confirm:
		get_viewport().set_input_as_handled()
		transition.emit(self,State.RELEASED)